﻿using System.Configuration;
using System.Web;
using System.Web.Mvc;

namespace Benecura.Interfaces.Web.Classes.Helper.Extensions
{
    public static class UrlHelperXtn
    {
        /// <summary>
        /// Get a route value
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="routeKey"></param>
        /// <returns></returns>
        public static object GetRouteValue(this UrlHelper helper, string routeKey)
        {
            return helper.RequestContext.RouteData.Values[routeKey];
        }

        /// <summary>
        /// Get a query string value
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="queryKey"></param>
        /// <returns></returns>
        public static string GetQueryString(this UrlHelper helper, string queryKey)
        {
            return HttpContext.Current.Request.QueryString[queryKey];
        }

        /// <summary>
        /// Get application name from web.config
        /// </summary>
        /// <param name="helper"></param>
        /// <returns></returns>
        public static string GetAppName(this UrlHelper helper)
        {
            return (string.IsNullOrEmpty(ConfigurationManager.AppSettings["ApplicationName"])) ? "UNKNOWN" : ConfigurationManager.AppSettings["ApplicationName"];
        }
    }
}